package com.alisoft.nano.seda;

import java.util.List;

import com.alisoft.nano.seda.notification.EventMachineNotificationListener;

/**
 * A machine combined by a set of stages that processing the work units.
 * 
 * @author zhimin.chenzm
 *
 * @param <T>
 */
public interface EventMachine<T> extends MBeanEnable {

    /**
     * Start this event machine
     */
	void start();

	/**
	 * Stop this event machine
	 */
	void stop();

	/**
	 * Check whether this event machine is started.
	 * @return
	 */
	boolean isStarted();

	/**
	 * Set the stages of the event machine
	 * 
	 * @param stage
	 */
	void setStages(List<Stage<T>> stage);
	
	/**
	 * 
	 * @param stage
	 */
	void addStage(Stage<T> stage);
	
	/**
	 * 
	 * @param listener
	 */
	void addEventMachineNotificationListener(EventMachineNotificationListener<T> listener);

	/**
	 * Post a work unit to this event machine with specified initial stage.
	 * 
	 * @param stageName the name of the initial stage
	 * @param workUnit the work unit to be processed
	 * 
	 * @throws InterruptedException
	 */
	void post(String stageName, T workUnit) throws InterruptedException;
}
